package com.kevin.common.util.tree;

import com.kevin.common.exception.BusinessException;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * ServletUtil
 *
 * @author wh
 * @date 2021-05-20
 */
public class RequestUtil {
    /**
     * 获取当前请求对象.
     *
     * @return HttpServletRequest
     */
    public static HttpServletRequest getRequest() {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if (requestAttributes == null) {
            throw new BusinessException("request not exist");
        }
        return ((ServletRequestAttributes) requestAttributes).getRequest();
    }

}
